package com.ruoyi.web.controller.dealrecord;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.dealrecord.domain.AmDealRecord;
import com.ruoyi.dealrecord.service.IAmDealRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 成交记录管理Controller
 * 
 * @author ruoyi
 * @date 2020-07-29
 */
@RestController
@RequestMapping("/dealrecord/dealrecord")
@Api(description = "成交记录管理")
public class AmDealRecordController extends BaseController
{
    @Autowired
    private IAmDealRecordService amDealRecordService;

    /**
     * 查询成交记录管理列表
     */
    @PreAuthorize("@ss.hasPermi('dealrecord:dealrecord:list')")
    @GetMapping("/list")
    @ApiOperation("查询成交记录管理列表")
    public TableDataInfo list(AmDealRecord amDealRecord)
    {
        startPage();
        List<AmDealRecord> list = amDealRecordService.selectAmDealRecordList(amDealRecord);
        return getDataTable(list);
    }

    /**
     * 导出成交记录管理列表
     */
    @PreAuthorize("@ss.hasPermi('dealrecord:dealrecord:export')")
    @Log(title = "成交记录管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出成交记录管理列表")
    public AjaxResult export(AmDealRecord amDealRecord)
    {
        List<AmDealRecord> list = amDealRecordService.selectAmDealRecordList(amDealRecord);
        ExcelUtil<AmDealRecord> util = new ExcelUtil<AmDealRecord>(AmDealRecord.class);
        return util.exportExcel(list, "dealrecord");
    }

    /**
     * 获取成交记录管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('dealrecord:dealrecord:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取成交记录管理详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(amDealRecordService.selectAmDealRecordById(id));
    }

    /**
     * 新增成交记录管理
     */
    @PreAuthorize("@ss.hasPermi('dealrecord:dealrecord:add')")
    @Log(title = "成交记录管理", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增成交记录管理")
    public AjaxResult add(@RequestBody AmDealRecord amDealRecord)
    {
        return toAjax(amDealRecordService.insertAmDealRecord(amDealRecord));
    }

    /**
     * 修改成交记录管理
     */
    @PreAuthorize("@ss.hasPermi('dealrecord:dealrecord:edit')")
    @Log(title = "成交记录管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改成交记录管理")
    public AjaxResult edit(@RequestBody AmDealRecord amDealRecord)
    {
        return toAjax(amDealRecordService.updateAmDealRecord(amDealRecord));
    }

    /**
     * 删除成交记录管理
     */
    @PreAuthorize("@ss.hasPermi('dealrecord:dealrecord:remove')")
    @Log(title = "成交记录管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除成交记录管理")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(amDealRecordService.deleteAmDealRecordByIds(ids));
    }

    /**
     * 成交记录审核
     * @param id 成交记录ID
     * @param auditStatus 审核状态 1审核中0拒绝2通过
     * @param reason 拒绝理由
     * @return
     */
    @RequestMapping(value = "/pc/updateAuditStatus",method = RequestMethod.GET)
    public AjaxResult updateAuditStatus(Integer id , Integer auditStatus , String reason){
        if ( 0!= amDealRecordService.updateAuditStatus(id,auditStatus,reason)){
            return AjaxResult.success("审核成功");
        }
        return AjaxResult.error("审核失败");
    }

    /**
     * 查看审核情况
     */
    @GetMapping("/getAuditSituation")
    @ResponseBody
    @ApiOperation("查看审核情况")
    public AjaxResult getAuditSituation(){
        return AjaxResult.success(amDealRecordService.getAuditSituation() );
    }
}
